package Project4;

import java.util.*;

class SwitchStatement extends Statement{
	private ArrayList<CaseStatement> statements = new ArrayList<CaseStatement>();
	private ArrayList<Statement> defaultStatements = new ArrayList<Statement>();
	private ExpressionAssignment expression;
	private int labelCounter = 0;

	public SwitchStatement(int l){
		labelCounter = l;
	}

	public void addStatement(CaseStatement s){
		statements.add(s);
	}

	public void addExpression(ExpressionAssignment e){
		expression = e;
	}

	public void addDefault(ArrayList<Statement> s){
		defaultStatements = s;
	}

	public String toString(){
		String r = "#SWITCH STATEMENT\n";
		int i = 0;

		for(CaseStatement c:statements){
			r += c.getHeader() + ", SWITCH_" + labelCounter + "_" + (i++) + "\n";
		}

		i = 0;
		r += "\n";
		for(CaseStatement c:statements){
			r += "SWITCH_" + labelCounter + "_" + (i++) + ":\n";
			r += c.getBody() + (c.broken ? "j SWITCH_END_" + labelCounter + "\n": "");
		}

		r += "#DEFAULT\n";
		for(Statement s: defaultStatements){
			r += s;
		}

		r += "SWITCH_END_" + labelCounter + ":\n\n";
		r += "#END SWITCH\n";
		return r;
	}
}
